package com.xiaoshuidi.cloud.module.rooms.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaoshuidi.cloud.framework.mybatis.core.mapper.BaseMapperX;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.iot.vo.DeviceReaVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @BelongsProject: lease-module-rooms
 * @BelongsPackage: com.xiaoshuidi.cloud.module.rooms.mapper
 * @Author: James
 * @CreateTime: 2023-05-26  16:15
 * @Description: TODO
 * @Version: 1.0
 */
public interface IotDeviceMapper extends BaseMapperX<DeviceReaVo> {
    @Select("select * from (SELECT DISTINCT " +
            " rm.device_third_no deviceThirdNo, rm.device_no deviceNo,rm.device_type deviceType,CONCAT(rh.area,CONCAT(rh.building_no,'栋'),case when rh.is_concentrated=0 then  CONCAT(rh.unit_no,'单元') else '' end,rh.name)roomName ,rm.deleted deleted" +
            " , rh.floor_no floorNo, rh.unit_no unitNo, rh.apartment_id  apartmentId, rh.apartment_area_id apartmentAreaId, rh.building_no buildingNo, is_concentrated isConcentrated,rh.name unitName,rh.area area , rh.is_whole isWhole, rh.super_id superId " +
            "FROM " +
            "room_sdiot_device_mapping rm " +
            "InNER JOIN room_house rh ON rm.room_house_id = rh.id )der " +
            "where ${ew.sqlSegment}")
    Page<DeviceReaVo> getDviceList(@Param("ew") QueryWrapper<?> wrapper, Page<?> page);

    @Select("select device_no from room_sdiot_device_mapping " +
            "where ${ew.sqlSegment}")
    List<String> getDviceByRoomId(@Param("ew") QueryWrapper<?> wrapper);

    @Select("select * from room_sdiot_device_mapping " +
            "where ${ew.sqlSegment}")
    List<DeviceReaVo> getDeviceMapping(@Param("ew") QueryWrapper<?> wrapper);

    @Select("select device_no from room_sdiot_device_mapping " +
            "where ${ew.sqlSegment}")
    String getDviceByDeviceType(@Param("ew") QueryWrapper<?> wrapper);

    @Select("select * from room_sdiot_device_mapping " +
            "where ${ew.sqlSegment}")
    List<DeviceReaVo> getDviceIds(@Param("ew") QueryWrapper<?> wrapper);

    @Select("select * from (SELECT DISTINCT " +
            " rm.device_third_no deviceThirdNo, rm.device_no deviceNo,rm.device_type deviceType,CONCAT(rh.area,CONCAT(rh.building_no,'栋'),case when rh.is_concentrated=0 then  CONCAT(rh.unit_no,'单元') else '' end,rh.name)roomName ,rm.deleted deleted" +
            " , rh.floor_no floorNo, rh.unit_no unitNo, rh.apartment_id  apartmentId, rh.apartment_area_id apartmentAreaId, rh.building_no buildingNo, is_concentrated isConcentrated,rh.name unitName,rh.area area , rh.is_whole isWhole, rh.super_id superId " +
            "FROM " +
            "room_sdiot_device_mapping rm " +
            "InNER JOIN room_house rh ON rm.room_house_id = rh.id )der " +
            "where ${ew.sqlSegment}")
    List<DeviceReaVo> getDviceListNoPages(@Param("ew") QueryWrapper<DeviceReaVo> wrapper);
}
